package com.maimao.goods.client.factory;

import com.maimao.core.enums.RespCode;
import com.maimao.core.model.resp.Result;
import com.maimao.goods.client.ShopClient;
import com.maimao.goods.client.UserClient;
import com.maimao.model.user.Shop;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author MaoLin Wang
 * @date 2020/11/30 10:03 下午
 */
@Component
@Slf4j
public class UserFallBackFactory implements FallbackFactory<UserClient> {

    @Override
    public UserClient create(Throwable cause) {
        String errorMsg = cause.getMessage() == null ? "" : cause.getMessage();

        return new UserClient() {
            @Override
            public Result<Integer> queryUserIntegral(String userId) {
                log.error("调用[UserClient-queryUserIntegral({})]出错 :{}", userId, errorMsg);

                return Result.fail(RespCode.FAIL, errorMsg);
            }


        };
    }
}
